using UnityEngine;
using UnityEngine.UI;

public class MainPanel : BasePanel
{
    [Header("按钮")]
    public Button gameButton;
    public Button aboutButton;
    public Button quitButton;
    public Button tipButton;
    public Button updateTipButton;
    public override void OnClose()
    {
        base.OnClose();
    }

    public override void OnInit()
    {
        base.OnInit();
        path="UI/Panel/MainPanel";

        GameManager.Instance.canOprate=false;

        AudManager.instance.PlayBgm(AudManager.instance.bgmDic["主页"]);
    }

    public override void OnShow(params object[] par)
    {
        base.OnShow(par);

        SeekUI();
    }
    //找到按钮
    public void SeekUI()
    {
        gameButton=item.transform.Find("StartGame").GetComponent<Button>();
        quitButton=item.transform.Find("Quit").GetComponent<Button>();
        aboutButton=item.transform.Find("About").GetComponent<Button>();
        tipButton=item.transform.Find("Tip").GetComponent<Button>();
        updateTipButton=item.transform.Find("UpdateTip").GetComponent<Button>();
        //按钮赋值
        quitButton.onClick.AddListener(QuitGame);
        gameButton.onClick.AddListener(StartGame);
        aboutButton.onClick.AddListener(About);
        tipButton.onClick.AddListener(TipButton);
        updateTipButton.onClick.AddListener(UpdateTipButton);
    }
    //退出
    public void QuitGame()
    {
        SaveManager.instance.SaveAllData();
        Application.Quit();

        AudManager.instance.PlayUIAud(AudManager.instance.uiDic["点击"], 1);
    }
    //开始游戏
    public void StartGame()
    {
        PanelManager.Open<ChooseDataPanel>();

        AudManager.instance.PlayUIAud(AudManager.instance.uiDic["点击"], 1);
    }
    //关于
    public void About()
    {
        PanelManager.Open<AboutPanel>();

        AudManager.instance.PlayUIAud(AudManager.instance.uiDic["点击"], 1);
    }
    //提示
    public void TipButton()
    {
        PanelManager.Open<PlayerTipPanel>();

        AudManager.instance.PlayUIAud(AudManager.instance.uiDic["点击"], 1);
    }
    //更新信息
    public void UpdateTipButton()
    {
        //打开版本信息
        PanelManager.Open<VersionPanel>();

        AudManager.instance.PlayUIAud(AudManager.instance.uiDic["点击"], 1);
    }

    public void Update()
    {
        if(GameManager.Instance.currLevelObj==null)
        {
            GameManager.Instance.canOprate=false;
        }
    }
}
